package com.study.d026effect;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.effect.BlurType;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.Effect;
import javafx.scene.effect.InnerShadow;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

/**
*@description
*@author xtayhame
*date 2020年3月21日
*version
*since v1.0
*/
public class InnerShadowMain extends Application{
	public static void main(String[] args) {
		launch(args);
	}
	@Override
	public void start(Stage stage) throws Exception {
		AnchorPane anchorPane = new AnchorPane	();
		HBox hBox = new HBox(20);
		Button button = new Button("测试阴影效果");
		Label label = new Label("测试阴影效果");
		Rectangle rectangle = new Rectangle(70, 70,Paint.valueOf("#218868"));
		Circle circle = new Circle(80);


		hBox.getChildren().addAll(button,label,rectangle,circle);

		//hBox.setEffect(getDropShadowEffect());

		anchorPane.getChildren().add(hBox);
		AnchorPane.setTopAnchor(hBox, 30.0);
		stage.setScene(new Scene(anchorPane, 800, 400));
		stage.show();

		 Effect effect=getInnerShadowEffect();
		 button.setEffect(effect);
		 label.setEffect(effect);
		 rectangle.setEffect(effect);
		 circle.setEffect(effect);
	}

	public Effect getInnerShadowEffect(){
		InnerShadow shadow = new InnerShadow();
		//设置阴影的颜色
		shadow.setColor(Color.valueOf("#0000CD"));
		//设置阴影的宽和高
		shadow.setHeight(30);
		shadow.setWidth(30);
		//设置阴影偏移效果（向左偏移）
		shadow.setOffsetX(10);
		//设置阴影偏移效果（向下偏移）
		shadow.setOffsetY(10);

		//设置阴影长度
		shadow.setRadius(20);
		//设置展开
		//dropShadow.setSpread(0.5);
		//设置模糊类型， 高斯模糊
		shadow.setBlurType(BlurType.GAUSSIAN);

		shadow.setChoke(0.5);

		//添加一个外投影
		shadow.setInput(new DropShadow());

		return shadow;
	}
}

